package com.api.user.controller;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.CoinTransaction;
import com.api.user.service.CoinTransactionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;



/**
* Created by wanghuiwen on 2021/03/26.
*/
@PowerEnable(name = "coin交易明细",url = "/coin/transaction")
@Api(value = "coin交易明细", tags = {"coin交易明细"})
@RestController
@RequestMapping("/coin/transaction")
public class CoinTransactionController extends Ctrl{
    @Resource
    private CoinTransactionService coinTransactionService;

    @ApiOperation(value = "coin交易明细详细信息", tags = {"coin交易明细"}, notes = "coin交易明细详细信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",required=true, value = "coin交易明细id", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/detail",name="coin交易明细详细信息")
    public Result detail(@RequestParam Integer id) {
        CoinTransaction coinTransaction = coinTransactionService.findById(id);
        return ResultGenerator.genSuccessResult(coinTransaction);
    }

    @ApiOperation(value = "coin交易明细列表信息", tags = {"coin交易明细"}, notes = "coin交易明细列表信息")
    @PostMapping(value = "/list/user", name = "coin交易明细列表信息")
    public Result list(@RequestParam(required = false) Long orderId,
                       @RequestParam(required = false) Integer transactionType,
                       @RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "{}") String order,
                       @RequestParam(defaultValue = "10") Integer size,
                       Authentication authentication) {
        Map<String,Object> params = new HashMap<>();
        params.put("orderId",orderId);
        params.put("transactionType",transactionType);
        params.put("userId",getAuthUser(authentication).getId());
        return coinTransactionService.listUser(params,order, page, size);
    }

    @ApiOperation(value = "coin交易明细列表信息", tags = {"coin交易明细"}, notes = "coin交易明细列表信息")
    @PostMapping(value = "/user/coins", name = "coin交易明细列表信息")
    public Result coins(@RequestParam(required = false) Long orderId,
                       @RequestParam(required = false) Integer transactionType,
                       @RequestParam() Long userId,
                       @RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "{}") String order,
                       @RequestParam(defaultValue = "10") Integer size,
                       Authentication authentication) {
        Map<String,Object> params = new HashMap<>();
        params.put("orderId",orderId);
        params.put("transactionType",transactionType);
        params.put("userId",userId);
        return coinTransactionService.listUser(params,order, page, size);
    }
}
